<?php

use yii\db\Migration;

/**
 * Class m181119_060912_rbac_new
 */
class m181119_060912_rbac_new extends Migration
{
    public function safeUp()
    {
        $this->createTable('auth_rule', array(
            "name" => 'varchar(64) primary key NOT NULL',
            "data" => 'text',
            "created_at" => 'int',
            "updated_at" => 'int',
        ));

        $this->createTable('auth_item', array(
            "name" => 'varchar(64) primary key NOT NULL',
            "type" => 'int',
            "description" => 'text',
            "rule_name" => 'varchar(64)',
            "data" => 'text',
            "created_at" => 'int',
            "updated_at" => 'int',
        ));

        $this->createTable('auth_item_child', array(
            "parent" => 'varchar(64) NOT NULL',
            "child" => 'varchar(64) NOT NULL',
        ));

        $this->createTable('auth_assignment', array(
            "item_name" => 'varchar(64) NOT NULL',
            "user_id" => 'varchar(64) NOT NULL',
            "created_at" => 'int',
        ));
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable('auth_rule');
        $this->dropTable('auth_item');
        $this->dropTable('auth_item_child');
        $this->dropTable('auth_assignment');
        echo "m181119_060912_rbac_new safe down.\n";
    }
}
